<?php
namespace Home\Controller;
class IndexController extends BaseController {
	public function __construct()
	{
		parent::__construct();
        //$lang = $_COOKIE['langType'];       //1英文
        //$menuGoods = [];
        $ver = 'cn';
        if($_COOKIE['langType'] == 1){
            $ver = 'en';
        }
        $menuGoods = M('goods_class')->where('')->field('gc_id,gc_name')->order('gc_sort asc')->select();
        foreach ($menuGoods as $k=>$v){
            $goods = M('goods')->where(['gc_id'=>$v['gc_id'],'goods_ver'=>$ver])->field('goods_id,goods_pic,goods_name,goods_key,goods_desc')->order('goods_sort asc')->select();
            foreach ($goods as $kk=>$vv){
                $goods[$kk]['goods_pic'] = '/Web/Uploads/'.$vv['goods_pic'];
                $goods[$kk]['goods_body'] = htmlspecialchars($vv['goods_body']);
            }
            $menuGoods[$k]['goods'] = $goods;
        }
        $this->assign('menuGoods',$menuGoods);
	}
    public function index()
	{
		$this->display();
    }

    public function support()
    {
        $ver = 'cn';
        if($_COOKIE['langType'] == 1){
            $ver = 'en';
        }
        $where = [];
        $where['ver'] = $ver;
        if(!empty(trim($_GET['searchText']))){
            $where['searchText'] = array('like','%'.trim($_GET['searchText']).'%');;
        }
        if(!empty(trim($_GET['searchSelectText']))){
            if(trim($_GET['searchSelectText']) != '全部'){
                $where['class'] = array('like','%'.trim($_GET['searchSelectText']).'%');
            }
        }
        $firmware = M('firmware')->where($where)->field('id,name,describe,download,utime')->order('ctime desc')->select();
        foreach ($firmware as $k=>$v){
            $firmware[$k]['download'] = $v['download'];
            $firmware[$k]['utime'] = date('Y-m-d H:i:s',$v['utime']);
        }

        $select = ["全部",'驱动包','BIOS和EC','显示驱动程序','声卡驱动程序','USB串行ATA驱动程序','芯片组','WiFi驱动程序','网络驱动程序','蓝牙驱动程序','软件程序','USB端口驱动','General Driver','其它驱动程序','操作指南','指纹驱动','操作系统','固件'];
        $this->assign('select',$select);

        $this->assign('firmware',$firmware);
        $this->display();
    }

    public function qualification(){
        $this->display();
    }

    public function about(){
        $this->display();
    }

    public function system(){
        if($_GET['type'] == 1){
            $seoname = "隐私政策";
        }else{
            $seoname = "条款细则";
        }
        $this->assign('seoname',$seoname);
        $this->display();
    }

    public function about_sub(){
        $data = [];
        $data['name'] = trim($_GET['name']);
        $data['email'] = trim($_GET['email']);
        $data['phone'] = trim($_GET['phoneNumber']);
        $data['propose'] = trim($_GET['desc']);
        $data['ctime'] = time();
        $data['utime'] = time();
        M('proposal')->add($data);
        $this->redirect('about');
    }

    public function detail(){
        $id = trim($_GET['goods_id']);
        $goods = M('goods')->where('goods_id='.$id)->field('goods_id,goods_name,goods_key,goods_desc,goods_body')->order('goods_sort asc')->find();
        $this->assign('goods',$goods);
        $this->display();
    }

    public function verify()
    {
        $config = array(
            'fontSize'    => 14,
            'length'      => 4,
            'imageW'      => 100,
            'imageH'    => 38,
            'useNoise' => false,
            //'useCurve' => false,
        );
        $verify = new \Think\Verify($config);
        $verify->entry(4);
    }

    /*public function goods(){
        $ver = trim($_GET['ver']);
        $class = M('goods_class')->where('')->field('gc_id,gc_name')->order('gc_sort asc')->select();
        foreach ($class as $k=>$v){
            $goods = M('goods')->where(['gc_id'=>$v['gc_id'],'goods_ver'=>$ver])->field('goods_id,goods_name,goods_key,goods_desc')->order('goods_sort asc')->select();
            foreach ($goods as $kk=>$vv){
                $goods[$kk]['goods_body'] = htmlspecialchars($vv['goods_body']);
            }
            $class[$k]['goods'] = $goods;
        }
        $this->ajaxReturn(['data'=>$class],'JSON');
    }

    public function goods_detail(){
        $id = trim($_GET['id']);
        $goods = M('goods')->where('goods_id='.$id)->field('goods_id,goods_name,goods_key,goods_desc,goods_body')->order('goods_sort asc')->find();
        $goods['goods_body'] = htmlspecialchars($goods['goods_body']);
        $this->ajaxReturn(['data'=>$goods],'JSON');
    }

    public function firmware(){
        $ver = trim($_GET['ver']);
        $where = [];
        $where['ver'] = $ver;
        if(!empty(trim($_GET['name']))){
            $where['name'] = array('like','%'.trim($_GET['name']).'%');;
        }
        $firmware = M('firmware')->where($where)->field('id,name,describe,download,utime')->order('ctime desc')->select();
        foreach ($firmware as $k=>$v){
            $firmware[$k]['download'] = '/Uploads/'.$v['download'];
            $firmware[$k]['utime'] = date('Y-m-d H:i:s',$v['utime']);
        }
        $this->ajaxReturn(['data'=>$firmware],'JSON');
    }

    public function inquiry(){
        $data = [];
        $data['name'] = trim($_POST['name']);
        $data['email'] = trim($_POST['email']);
        $data['phone'] = trim($_POST['phone']);
        $data['propose'] = trim($_POST['propose']);
        $data['ctime'] = time();
        $data['utime'] = time();
        M('proposal')->add($data);
        $this->ajaxReturn([],'JSON');
    }*/




}